#pragma once
#include "Drawable.h"
#include "Element.h"
#include "Position.h"
#include "Texture.h"
#include <list>
#include "color.h"
#include "Ball.h"
#define RAIL_HEIGHT 20
#define PI 3.14159265

class Rail : public Element, public Drawable{
	
	/*----------------Atributos-------------------------*/	
	private: list<Position*> * points;    

	private: list<Ball*> * balls;

	private: Texture *texture;
	
	private: float height;

	private: Color * elementColor;
			 Position * position;
			 Color * lineColor;

	/*--------------Constructores----------------------*/		
	
	public: Rail();
	
	/*-------------Getters & Setters--------------------*/	
	public: virtual Texture* getTexture();

	public: virtual void setTexture(Texture *texture);

	public: virtual void setElementColor(Color * color);

	public: virtual Color * getElementColor();

	public: virtual Color * getLineColor();

	public: virtual void setLineColor(Color * color);

	public: virtual void setPosition(Position * position);

	public: virtual Position * getPosition();

	public: virtual void setPoints(list<Position*> * points);

	public: virtual list<Position*> * getPoints();
	
	public: virtual float getNextAngle(int pointNumber);

	public: virtual float getMinXPos();
	
	public: virtual float getMinYPos();
	
	public: virtual float getMaxXPos();
	
	public: virtual float getMaxYPos();
	
	public: virtual float getHeight();
	
	public: virtual void setHeight(float height);

	/*-------------Metodos------------------------------*/	
	public: void draw();

	public: virtual void addPoint(Position *position);

	public: virtual void addBall(Ball *ball);

	public: virtual void removeBall(Ball *ball);

	public: virtual void removePoint(Position *position);    

	public:	int checkBallAndRailIntersection( Ball* ball);

	public:	int checkBallAndRailBallsCollision( Ball* ball);

	private:	Collision * evaluateIntersectionEdge( Ball * ball, Position * point1, Position * point2);
				int getPixelXIntersection(float m1, float b1, float m2, float b2 );
				int fx(int x, float m, float o);
				int sign(int value);
	/*-----------------Destructor-----------------------*/			
	public:	virtual ~Rail();
			void setBalls( list<Ball*>* balls );
			list<Ball*> * getBalls();
};
